import * as chalk from 'chalk';
import { Command } from 'commander';

import { ERROR_PREFIX } from '../ui';
import { TemplateGenerateCommand } from './template/generate/generate';
import { FileLogCommand } from './project/log/git-log';

export class CommandLoader {
	public static load(program: Command): void {
		new TemplateGenerateCommand().load(program);
		new FileLogCommand().load(program);
		this.handleInvalidCommand(program);
	}

	private static handleInvalidCommand(program: Command) {
		program.on('command:*', () => {
			console.error(
				`\n${ERROR_PREFIX} Invalid command: ${chalk.red('%s')}`,
				program.args.join(' ')
			);
			console.log(
				`See ${chalk.red('--help')} for a list of available commands.\n`
			);
			process.exit(1);
		});
	}
}
